package com.touna.thread;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

public class CrawlerRun {



   public static void main(String[] args) {
      ScheduledExecutorService service = Executors.newScheduledThreadPool(8);//先定义8个线程空间
      final ScheduledFuture<?> future = service.scheduleAtFixedRate(new CrawlerTest(0), 0,2,
                 TimeUnit.SECONDS);//CrawlerTest()是一个实现Runnable接口的类，会自动运行里面的run()方法，0的意思就是启动等待时间，这里就是直接运行，

      //使用1个线程
         Thread t= new Thread(new Runnable() {
                public void run() {
                    try {
                        future.get();
                    } catch (Exception e) {
                        future.cancel(false);//关闭线程
                    }
                }
        });
        t.start() ;

   }
}